<template>
  <div style="line-height: 60px; display: flex">
    <div style="flex: 1">
      <span
        :class="collapseBtnClass"
        style="cursor: pointer; font-size: 22px"
        @click="collapse"
        ><el-icon> <fold /></el-icon
      ></span>
      <el-breadcrumb
        separator="/"
        style="display: inline-block; margin-left: 10px; font-size: 18px"
      >
        <el-breadcrumb-item :to="'/'">首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{ currentPathName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <el-dropdown style="width: 200px; cursor: pointer; text-align: center">
      <div style="display: inline-block">
        <meta name="referrer" content="no-referrer" />
        <img
          :src="user.avatarUrl"
          alt=""
          style="
            width: 30px;
            border-radius: 50%;
            position: relative;
            top: 10px;
            right: 5px;
          "
        />
        <span>{{ user.nickname }}</span>
        <el-icon style="margin-left: 5px; margin-top: 23px">
          <arrow-down />
        </el-icon>
      </div>
      <template #dropdown>
        <el-dropdown-menu style="width: 100px; text-align: center">
          <el-dropdown-item
            ><router-link
              to="/password"
              style="text-decoration: none; color: black"
              >密码修改</router-link
            ></el-dropdown-item
          >
          <el-dropdown-item
            ><router-link
              to="/person"
              style="text-decoration: none; color: black"
              >个人信息</router-link
            ></el-dropdown-item
          >
          <el-dropdown-item 
            ><span style="text-decoration: none" @click="logout()"
              >退出</span
            ></el-dropdown-item
          >
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
<script>
export default {
  name: "Header",
  props: { collapseBtnClass: String, collapse: Boolean, user: Object },
  data() {
    return {
      // user: localStorage.getItem("user")
      //   ? JSON.parse(localStorage.getItem("user"))
      //   : {},
      //currentPathName: "",
      // paths: [
      //   { path: "/", name: "首页" },
      //   { path: "/user", name: "用户管理" },
      //   { path: "/user/add", name: "添加用户" },
      // ],
    };
  },
  created() {
    //console.log(this.$route.name);
  },
  methods: {
    logout() {
      this.$store.commit("logout");
      // localStorage.removeItem("user");
      // this.$router.push("/login");
      this.$message.success("退出成功");
    },
  },
  computed: {
    currentPathName() {
      return this.$store.state.currentPathName; //需要监听的数据
    },
  },
  watch: {
    currentPathName2(newVal, oldVal) {
      console.log(newVal);
      //console.log(this.currentPathName);
    },
  },
};
</script>
<style scoped>
:deep(.el-tooltip__trigger:focus-visible) {
  outline: unset;
}
</style>
